package cn.tedu.demo1.cn.tedu;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class BMIController {
    /*
        /bmi 等效 value = "/bmi" 也等效 path = "/bmi"
     */
    @RequestMapping(path = "/bmi", produces = "text/html;charset=utf-8")
    @ResponseBody       //通过返回值的方式 给客户端响应数据
    public String bmi(HttpServletRequest request) throws IOException {
        String height = request.getParameter("h");
        String weight = request.getParameter("w");
        float h = Float.parseFloat(height);
        float w = Float.parseFloat(weight);
        float num = w/(h*h);
        String info = null;
        if(num < 18.5){
            info = "您的体重偏瘦";
        }else if(num < 24){
            info = "您的体重正常";
        }else if(num < 28){
            info = "您的体重偏胖";
        }else{
            info = "您因该适当的减肥了";
        }

//        response.setContentType("text/html;charset=utf-8");
//
//        PrintWriter pw = response.getWriter();
//
//        pw.println(info);
//
//        pw.close();
        return info;

    }


}
